package com.ete.app.app

import android.os.Build
import com.elvishew.xlog.XLog
import com.ete.app.BuildConfig
import com.ete.app.R
import com.ete.app.constant.EteConstant
import com.ete.service.entry.hardware.HardwareEntry
import com.ete.service.entry.log.AppLogEntry
import com.ete.service.entry.version.VersionEntry
import com.ete.service.manager.hardware.HardwareManager
import com.ete.service.manager.location.LocationManager
import com.ete.service.manager.log.LogManager
import com.ete.service.manager.version.VersionManager
import com.ete.service.util.log.EteLog
import com.jkkc.lib.base.core.BaseApplication
import com.jkkc.lib.base.extend.BOOLEAN_FALSE
import com.tencent.mmkv.MMKV
import com.tencent.mmkv.MMKVLogLevel

/**
 * @author:LiXian
 *
 * Desc:application
 * Version:1.0 设备使用地域异常
 * date 2024/1/8 10:44
 */
class EteApplication : BaseApplication() {

    override fun onCreate() {
        super.onCreate()
        XLog.init()
        initMMKV()
//        WriterLocalUtils.initWritePath(EteConstant.CASH_LOG, EteConstant.CASH_SCORE)

        //初始化日志上报
        val mAppLogEntry = AppLogEntry(
                mAppType = "UP_APP_002",
                mAppThemeColor = R.color.teal_200,
                mAppDirs = mutableListOf(
                        EteConstant.DB, EteConstant.CRASH, EteConstant.CASH_LOG,
                        EteConstant.CASH_SCORE, EteConstant.CASH_TXT
                ),
                mZipPassword = "123456",
                mAppHostPath = EteConstant.DIR,
                mDefaultUploadDirs = mutableListOf(EteConstant.DB),
                deviceId = Build.SERIAL
        )
        EteLog.d("缓存下载目录download:[${EteConstant.CASH_LOG}]")
        LogManager.init(mAppLogEntry)

        //初始化版本更新
        val mVersionEntry = VersionEntry(
                mAppType = "UP_APP_001",
                mAppThemeColor = R.color.teal_200,
                mAppPathDir = EteConstant.DOWNLOAD,
                isSilentInstall = BOOLEAN_FALSE
        )
        VersionManager.init(mVersionEntry)

        //初始化硬件上报
        val mHardwareEntry = HardwareEntry(
                mThemeColor = R.color.teal_200,
                mDBPath = EteConstant.DB,
                deviceId = Build.SERIAL
        )
        HardwareManager.init(mHardwareEntry)

        LocationManager.initLocation()

        //是否Debug模式（1、debug模式使用测试服务器  2、否则，使用正式服务器）
        com.ete.service.manager.platform.PlatformManager.setIsDebug(BuildConfig.PLATFORM_IS_DEBUG)

        recorderLogActivity.add("MainActivity")
    }

    private fun initMMKV() {
        val rootDir: String = MMKV.initialize(BaseApplication.getInstance())
        val level = if (BuildConfig.DEBUG) {
            MMKVLogLevel.LevelDebug
        } else {
            MMKVLogLevel.LevelError
        }
        MMKV.setLogLevel(level)
        EteLog.i("MMKV Init mmkv success, root dir:$rootDir")
    }
}